#define _CRT_SECURE_NO_WARNINGS   1

#include"stack.h"
void StackInit(Stack* st) {
	st->a = NULL;
	st->capacity = 0;
	st->top = 0;

}

void StackInsert(Stack* st, StackType val)
{
	
	if (st->top == st->capacity)
	{
		int newcapacity = st->capacity == 0 ? 4 : 2 * st->capacity;
		StackType*tmp = realloc(st->a, newcapacity * sizeof(StackType));
		if (tmp==NULL)
		{
			perror("realloc");
			return ;
		}
		else {
			st->capacity = newcapacity;
			st->a = tmp;
		}
		
	}
	st->a[st->top] = val;
	st->top++;
}
void StackPop(Stack* st)
{
	assert(!StackEmpty(st));
	st->top--;
}
int StackSize(Stack* st)
{
	assert(!StackEmpty(st));
	return st->top;
}
StackType StackTop(Stack* st)
{
	assert(!StackEmpty(st));
	return st->a[st->top-1];
}
bool StackEmpty(Stack* st)
{
	return st->top == 0;
}
void StackDestroy(Stack* st)
{
	if(st->top!=0)
	free(st->a);

}




